package model

import (
	"box-ma-fresh/boxrpc/boxrpc"
	"gorm.io/gorm"
)

type GoodsType struct {
	gorm.Model
	TypeName string `gorm:"type:varchar(20);comment:类型名称"`
}

func (t *GoodsType) GoodsTypeAdd(db *gorm.DB) error {
	return db.Debug().Create(t).Error
}

func (t *GoodsType) GoodsTypeDetail(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(t).Error
}

func (t *GoodsType) GoodsTypeDel(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Delete(t).Error
}
func GoodsTypeList(db *gorm.DB, in *boxrpc.GoodsTypeListRequest) []*boxrpc.GoodeTypeList {
	var list []*boxrpc.GoodeTypeList
	db.Debug().Model(&GoodsType{}).
		Select(
			"goods_types.id goods_type_id",
			"goods_types.type_name",
		).
		Scopes(Paginate(int(in.Page), int(in.Size))).Find(&list)
	return list
}
